import java.util.Iterator;


public class SequenceIterator<T> implements Iterator<T> {

	CircularArraySequence<T> seqCopy;
	int position;
	
	public SequenceIterator(CircularArraySequence<T> seq) {
		seqCopy = new CircularArraySequence<T>(seq);
		position = seqCopy.head;
	}
	
	@Override
	public boolean hasNext() {
		if(position == seqCopy.last)
			return false;
		else if(position == seqCopy.last + 1)
			return false;
		else	
			return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	public T next() {
		if(position == seqCopy.array.length - 1) {
			position = 0;
			return (T) seqCopy.array[seqCopy.array.length-1];
		}
		else if(position == 0) {
			position++;
			return (T) seqCopy.array[position-1];
		}
		else {
			position++;
			return (T) seqCopy.array[position-1];
		}
	}

	@Override
	public void remove() throws UnsupportedOperationException {
		// TODO Auto-generated method stub
		
	}

}
